package com.hrc.springbootdemo;

import com.hrc.springbootdemo.async.AsycService;
import com.hrc.springbootdemo.async.FutureTaskService;
import com.mzt.logapi.starter.annotation.EnableLogRecord;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.socket.config.annotation.EnableWebSocket;

import java.net.InetAddress;
import java.net.UnknownHostException;


@SpringBootApplication(exclude = {RedissonAutoConfiguration.class})
@EnableWebSocket
@Slf4j
@EnableLogRecord(tenant = "com.hrc.demo")
public class SpringbootDemoApplication implements CommandLineRunner {
    @Resource
    private FutureTaskService futureTaskService;
    @Resource
    private AsycService asycService;

    public static void main(String[] args) throws UnknownHostException {

        ConfigurableApplicationContext context = SpringApplication.run(SpringbootDemoApplication.class, args);
        String path = context.getEnvironment().getProperty("server.servlet.context-path");
        String port = context.getEnvironment().getProperty("server.port");
        String ip = InetAddress.getLocalHost().getHostAddress() ;
        log.info("接口文档地址: http://{}:{}{}/doc.html", ip,port, path);

    }

    @Override
    public void run(String... args) throws Exception {
        log.info("Thread.currentThread().getName() = {}" ,Thread.currentThread().getName());
        log.info("asycService.async().join() = {}" , asycService.async().join());
        futureTaskService.test();
    }
}
